<template>
	<view class="container flex fdc jcsb">
		<uv-navbar placeholder bgColor="transparent">
      <view slot="left">
        <image class="back" src="../../../static/back.png" mode="" @click="pageBack"></image>
      </view>
    </uv-navbar>
		
		<view class="login-box">
			<image class="loginbg" src="../../../static/tab31.png" mode=""></image>
			<!-- <view class="btn btn1" @click="mobileLogin">手机号登录</view> -->
			<view class="pr">
				<view class="btn btn2" @click="wxLogin">
					
					<text v-if="lang==0">
						手机号快捷登陆
					</text>
					<text v-if="lang==1">
						Login with mobile phone number
					</text>
				</view>
				<!-- <button type="default" open-type="getUserInfo" class="btn btn2 profilebtn" @getuserinfo="getUserInfo">微信授权登录</button> -->
			</view>
		</view>
	</view>
	
</template>
<script>
	export default {
		data() {
			return {
				invite_code: '', //邀请码
				lat:'34.768438',
				lng:'113.516931',
				lang:0
			};
		},
		onShow() {
			let lang = uni.getStorageSync('lang')
			if(lang){
				this.lang = lang
			}
		},
		onLoad() {
			let _this = this;
			if(uni.getStorageSync('inviteCode')) {
				this.invite_code = uni.getStorageSync('inviteCode');
			}
			
			// uni.getSetting({
			//     success(res) {
			// 		console.log(res);
			// 	    if(res.authSetting['scope.userInfo']) {
			// 			if(_this.$store.state.token) {
			// 				uni.switchTab({
			// 					url: '../../home/index/index'
			// 				})
			// 			}
			// 	    }
			//     }
			// })
		},
		methods: {
			// 返回
			pageBack() {
				uni.navigateBack();
			},
			// 手机号登录
			mobileLogin() {
				uni.navigateTo({
					url: '../mobileLogin/mobileLogin'
				})
			},
			// 微信授权登录(这个方法已废弃,用下面那个)
			getUserInfo() {
				let _this = this;
				uni.showLoading({
					title: 'loading'
				});
				uni.login({
					provider: 'weixin',
					success: (res2) => {
						console.log(res2.code);
						
					},
				})
			},
			getLocation () {
							let that = this;
				                uni.getLocation({
				                    type: 'wgs84',
				                    altitude: true,
				                    success: function(res) {
				                        console.log(res, "经纬度授权")
											
												that.lng = res.longitude
												that.lat = res.latitude
												// uni.showLoading({ title: '正在加载', mask: true });
												that.wxLogin();
												
										   // that.$refs.popup.open()
									
				                        // that.addressTop = "定位中..."
				                        // that.getPlistData.lat = res.latitude;
				                        // that.getPlistData.lng = res.longitude;
				
				                     
				                    },
				                    fail: function(res) {
										
				                        console.log(res, "经纬度没有授权")
				                        uni.getSetting({
				                            success: (res) => {
				                                let authSetting = res.authSetting;
				                                if (!res.authSetting['scope.userLocation']) {
				                                    uni.showModal({
				                                        title: 'Vol需要获取您的位置',
				                                        // content: '您的位置信息将用于小程序匹配刷脸上网服务开通的城市',
				                                        success: (res)=> {
				                                            if (res.confirm) {
				                                                uni.openSetting()
				                                            }
				                                        }
				                                    })
				                                } else {
				                                    uni.showModal({
				                                        title: 'Vol需要获取您的位置',
				                                        // content: '您的位置信息将用获取信息',
				                                        success: (res) => {
				                                            if (res.confirm) {
				                                                uni.openSetting()
				                                            }
				                                        }
				                                    })
				                                }
				                            }
				                        })
				                    }
				                });
								
								
				// uni.getLocation({
				// 	type: 'wgs84',
				// 	success:  (res)=> {
				// 		this.user.jingdu = res.longitude
				// 		this.user.weidu = res.latitude
				// 	}
				// });
			},
			// 微信授权登录
			wxLogin() {
				var _this = this;
				
				
				if(this.lng == ""){
					this.getLocation();
					return;
				}
				uni.showLoading({
					title: 'loading',
					mask:true
				});
				//登陆
				uni.login({
				  provider: 'weixin',
				  success: function (loginRes) {
				    console.log(_this.lng,7777777);
					
					_this.$api.request('/api/user/wxlogin', {
						code:loginRes.code,
						lng:_this.lng,
						lat:_this.lat
					}, '', function(res){
						console.log(res);
						
						if(res.code == 1) {
							uni.setStorageSync('user_type', res.data.type);
							uni.setStorageSync('token', res.data.token);
							//_this.$store.commit('setToken', res.data.userinfo.token);
							_this.$store.commit('setToken', res.data.token);
								uni.hideLoading(); //隐藏loading
								uni.switchTab({
									url: '/pages/home/index/index'
								})
						
						}else{
							uni.showToast({
								title: res.msg,
								icon:"none"
							})
						}
					});
				    // 获取用户信息
				    // uni.getUserInfo({
				    //   provider: 'weixin',
				    //   success: function (infoRes) {
				    //     console.log(infoRes.userInfo);
				    //   }
				    // });
				  }
				});
				///api/we_chat/submit_order
				
				// this.$api.request('/api/we_chat/unified_order', {
				// 	order_sn:'202108132324504'
				// }, '', function(res){
				// 	console.log(res);
				// 	uni.showToast({
				// 		title: res.msg
				// 	})
				// 	if(res.code == 200) {
					
				// 	}
				// });
				// //分享
			
				//ffmpeg -y -i 16279589575400.mp4 -vcodec copy -acodec copy -vbsf h264_mp4toannexb /www/wwwroot/zjjy.dykjcloud.com/public/uploads-video/video/16279589575400.ts
				///ffmpeg-3.4/ffmpeg -ss 0 -t 1:6:32 -i 16279589575400.ts -c copy -map 0 -f segment -segment_list 16279589575400.m3u8 -segment_time 60 16279589575400-%03d.ts
				//ffmpeg.exe -i D:\zhibo\video\douyin.mp4 -vcodec copy -bsf h264_mp4toannexb -f h264 douyin.h264
				// uni.requestPayment({
				//     provider: 'wxpay ',//alipay  
				//     orderInfo: 'orderInfo', //微信、支付宝订单数据 【注意微信的订单信息，键值应该全部是小写，不能采用驼峰命名】
				//     success: function (res) {
				//         console.log('success:' + JSON.stringify(res));
				//     },
				//     fail: function (err) {
				//         console.log('fail:' + JSON.stringify(err));
				//     }
				// });

			}
		}
	}
</script>

<style lang="scss">
	.container {
		background:url("https://www.hdlddzkj.com/02.jpg");
		background-size: 100%;
		width: 100%;
		padding: 0 50rpx 190rpx;
		height: 100vh;
		box-sizing: border-box;
		.back {
			margin-top: 4rpx;
			width: 20rpx;
			height: 36rpx;
		}
		.loginbg {
			width: 80px;
			height: 80px;
			margin: 0 auto;
		}
		.login-box {
			
			position: fixed;
			top:25%;
			width: 86%;
			.btn {
				margin: 0;
				font-weight: bold;
			}
			.btn1 {
				color: #769CFF;
				background: #fff;
			}
			.pr {
				margin-top: 160rpx;
				width: 100%;
				height: 88rpx;
				.btn2 {
					background:#507afe;
					position: absolute;
					top: 0;
					left: 0;
					// border: 2rpx solid #fff;
					color: #fff;
				}
				.profilebtn {
					opacity: 0;
				}
			}
		}
	}
</style>
